<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账单日期" prop="billDateInfo">
        <el-date-picker clearable v-model="queryParams.billDateInfo" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="merchantInfoHisList">

      <el-table-column label="账户名称" align="center" prop="accountName">
        <template slot-scope="scope">
          {{ scope.row.accountName }}[{{ scope.row.accountId }}]
        </template>
      </el-table-column>

      <el-table-column label="操作类型" align="center" prop="actionTypeName">
        <template slot-scope="scope">
          <span :style="{ 'color': getTextColor(scope.row.actionTypeStr) }">{{ scope.row.actionTypeStr }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改金额" align="center" prop="changeAmount">
        <template slot-scope="scope">
          <span :style="{ 'color': scope.row.changeAmount < 0 ? 'red' : 'green' }">{{ scope.row.changeAmount }}</span>
        </template>
      </el-table-column>
      <el-table-column label="原金额" align="center" prop="originAmount" />
      <el-table-column label="现金额" align="center" prop="currentAmount">
        <template slot-scope="scope">
          <span :style="{ color: scope.row.currentAmount < 500 ? 'red' : 'green' }">
            {{ scope.row.currentAmount }} ￥
          </span>
        </template>
      </el-table-column>
      <el-table-column label="账单日期" align="center" prop="billDateInfo" />
      <el-table-column label="操作时间" align="center" prop="creatorId">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime) }}
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { listMerchantInfoHis } from "@/api/account/merchantInfoHis";

export default {
  name: "MerchantInfoHis",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户账户流水表格数据
      merchantInfoHisList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dateInfo: null,
        billDateInfo: null,
        accountId: null,
        accountName: null,
        actionType: null,
        changeAmount: null,
        originAmount: null,
        currentAmount: null,
        dataInfo: null,
        remarkInfo: null,
        opertorId: null,
        opertorName: null,
      },
      // 表单参数
      form: {},

    };
  },
  created() {
    this.getList();
  },
  watch: {
    $route() {
      this.getList()
    }
  },
  methods: {
    /** 查询商户账户流水列表 */
    getList() {
      this.loading = true;
      const accountId = this.$route.query.accountId;
      this.queryParams.accountId = accountId;
      listMerchantInfoHis(this.queryParams).then(response => {
        this.merchantInfoHisList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    }, 
    getTextColor(actionType) {
      return actionType === "消耗" || actionType === "退款" ? 'red' : 'green';
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dateInfo: null,
        billDateInfo: null,
        accountId: null,
        accountName: null,
        actionType: null,
        changeAmount: null,
        originAmount: null,
        currentAmount: null,
        dataInfo: null,
        remarkInfo: null,
        opertorId: null,
        opertorName: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('account/merchantInfoHis/export', {
        ...this.queryParams
      }, `merchantInfoHis_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
